package com.gitee.wsl.ext.list


fun <T: Any> MutableList<T?>.computeIfAbsent(index: Int, f: () -> T): T {
    var n = this.size
    while (n <= index) {
        add(null)
        n += 1
    }

    var res = this[index]
    if (res == null) {
        res = f()
        this[index] = res
    }

    return res
}